package com.gome.axwl.aoc.web.controller.mq.consumer;

import com.cloudzone.cloudmq.api.open.base.Action;
import com.cloudzone.cloudmq.api.open.base.ConsumeContext;
import com.cloudzone.cloudmq.api.open.base.Msg;
import com.cloudzone.cloudmq.api.open.base.MsgListener;
import com.gome.axwl.aoc.entity.mq.ImPushMsgMQEntityV31;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.util.Properties;

/**
 * Created with IntelliJ IDEA.
 * User: wanglinyong
 * Date: 2016/12/28
 * Time: 17:30
 *
 * @Copyright(c) gome inc Gome Co.,LTD
 */
public class MsgConsumerListener implements MsgListener {
    private static Logger logger = LoggerFactory.getLogger(MsgConsumerListener.class);
    @Autowired
    private Properties configProperties;
    @Value("${gomeAxwlAocDriverIntegrationTag}")
    private String gomeAxwlAocDriverIntegrationTag;
    @Autowired
    DriverIntegrationConsumerTask driverIntegrationConsumerTask;

    @Override
    public Action consume(Msg msg, ConsumeContext consumeContext) {
       logger.info("=========================mq监听器开始执行================");
        String tag = msg.getTags();

        if (StringUtils.equals(tag, gomeAxwlAocDriverIntegrationTag)) {
            logger.debug("消费到axwl-aoc的mq消息,tag:{},message:{}", tag, consumeContext);
            return driverIntegrationConsumerTask.consume(msg, consumeContext, ImPushMsgMQEntityV31.class);
        }else {
            logger.error("消费到非axwl-aoc的mq消息,tag:{},message:{}", tag);
            return null;
        }
    }
}
